package com.chuangke.file.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.chuangke.common.http.HttpResult;
import com.chuangke.file.model.FileBrief;
import com.chuangke.file.model.FileChunk;
import com.chuangke.file.service.FileTransferService;

@RestController
@RequestMapping("/transfer")
public class FileTransferController {

	@Autowired
	private FileTransferService fileTransferService;

	/**
	 * 秒传接口
	 */
	@PostMapping("/quick")
	public HttpResult secondUpload(FileBrief fileBrief) {
		return HttpResult.ok(fileTransferService.secondUpload(fileBrief));
	}

	/**
	 * 分块上传
	 */
	@PostMapping("/chunk")
	public HttpResult uploadChunk(FileChunk fileChunk) {
		fileTransferService.uploadChunk(fileChunk);
		return HttpResult.ok();
	}

	/**
	 * 分块上传合并
	 */
	@PostMapping("/merge")
	public HttpResult mergeFile(@RequestBody FileBrief fileBrief) {
		fileTransferService.mergeFile(fileBrief);
		return HttpResult.ok();
	}

}
